package sealte.hvpms.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import sealte.util.database.conn.DBINFOReader;

public class DBConnection {
	
	private static String configFilePath = DBConnection.class.getResource("").getPath()+"../config/DBINFO.xml";
	private static DBINFOReader info = null;
	
	static{
		try {
			info = new DBINFOReader(configFilePath,"MYSQL_LOCAL");
			info.doInitialize();
			Class.forName(info.driverName);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private DBConnection(){}
		
	public static Connection getConnection() throws Exception {
		return DriverManager.getConnection(info.url, info.user, info.password);
	}
	
	public static void close(ResultSet rs,PreparedStatement ps,Connection conn){
		try{
			if(null!=rs){
				rs.close();
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try{
				if(null!=ps){
					ps.close();
				}
			}catch(Exception ex){
				ex.printStackTrace();
			}finally{
				try{
					if(null!=conn){
						conn.close();
					}
				}catch(Exception exx){
					exx.printStackTrace();
				}
			}
		}
	}
}
